package com.lzm.ydpt.module.common;

import android.Manifest;
import android.view.View;

import com.byt.framlib.base.BaseActivity;
import com.byt.framlib.commonutils.SharePerUtils;
import com.byt.framlib.commonutils.permission.PermissionReq;
import com.byt.framlib.commonutils.permission.ResultListener;
import com.byt.framlib.commonwidget.onclicktwo.AntiShake;
import com.lzm.ydpt.LoginActivity;
import com.lzm.ydpt.Constants;
import com.lzm.ydpt.Dapplication;
import com.lzm.ydpt.R;
import com.lzm.ydpt.entity.UserInfo;
import com.lzm.ydpt.module.mall.activity.MallMainActivity;
import com.lzm.ydpt.module.order.activity.UserMainActivity;
import com.lzm.ydpt.module.riding.activity.RidingMainActivity;
import com.lzm.ydpt.mvp.contract.WelContract;
import com.lzm.ydpt.mvp.presenterimpl.WelPresenterImpl;
import com.lzmpt.imchat.ui.MainActivity;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.OnClick;
import okhttp3.RequestBody;

public class WelActivity extends BaseActivity<WelPresenterImpl> implements WelContract.View {
    @Override
    public int getLayoutId() {
        return R.layout.activity_welcome;
    }

    @Override
    public WelPresenterImpl initPreData() {
        return new WelPresenterImpl(this);
    }

    @Override
    public void initView() {
        setView();

    }

    private void setView() {
        PermissionReq.with(this)
                .permissions(Manifest.permission.READ_EXTERNAL_STORAGE,
                        Manifest.permission.WRITE_EXTERNAL_STORAGE,
                        Manifest.permission.ACCESS_COARSE_LOCATION,
                        Manifest.permission.ACCESS_FINE_LOCATION,
                        Manifest.permission.READ_PHONE_STATE)
                .result(new ResultListener() {
                    @Override
                    public void onGranted() {
                        // 删除日志
                    }

                    @Override
                    public void onDenied() {

                    }
                }).request();
    }

    @OnClick({R.id.img_qx, R.id.img_xd, R.id.img_sc, R.id.img_grxx, R.id.img_imchat})
    public void onClick(View view) {
        if (AntiShake.check(view.getId())) {
            return;
        }
        switch (view.getId()) {
            case R.id.img_imchat:
                openActivity(MainActivity.class);
                break;
            case R.id.img_qx:
                openActivity(RidingMainActivity.class);
                break;
            case R.id.img_xd:
                openActivity(UserMainActivity.class);
                break;
            case R.id.img_sc:
                openActivity(MallMainActivity.class);
                break;
            case R.id.img_grxx:
                Map map = new HashMap();
                map.put("username", "app");
                map.put("password", "123456");
                JSONObject json = new JSONObject(map);
                RequestBody requestBody = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), json.toString());
                mPresenter.onWel(requestBody);
                break;
        }
    }

    @Override
    public void onWel(List<UserInfo> infoList) {
        if (infoList != null && infoList.size() > 0) {
            Dapplication.setUserInfo(infoList.get(0));
            SharePerUtils.setSharedString(Constants.USER_TOKEN, infoList.get(0).getToken());
        }
    }

    @Override
    public void showMessage(String message, String method) {

    }

    @Override
    public void showErrorView(String msg) {

    }
}
